#pragma once
#include "uart/ProtocolSender.h"
#include "water/typedef.h"
#include "manager/ConfigManager.h"
#include "storage/StoragePreferences.h"
#include "ntp/ntp.h"
#include "common.h"
#include "logic_utility.hpp"
#include "net/NetManager.h"
#include "utils/TimeHelper.h"
#include "utils/ScreenHelper.h"


#define WIFIMANAGER			NETMANAGER->getWifiManager()


//wifi等级强度
int Levl= 5;
//正在制冷中
bool isOpenningCold = false;
//滤芯快检
extern bool FlagLvxin;

Mutex mWifiLevl;
//保存信号强度
void SaveLev(const int levl){
	Mutex::Autolock _l(mWifiLevl);
	Levl=levl;
}
//返回保存信号强度
int RetLev(){
	Mutex::Autolock _l(mWifiLevl);
	return Levl;
}

Mutex mWiFiInfoMutex;


namespace { // 加个匿名作用域，防止多个源文件定义相同类名，运行时冲突

//实现长按监听接口
class LongClickListener : public ZKBase::ILongClickListener {

	virtual void onLongClick(ZKBase *pBase) {
		LOGD("触发长按事件");
		EASYUICONTEXT->openActivity("valveActivity");
		EASYUICONTEXT->hideStatusBar();
	}
};
static LongClickListener longButtonClickListener;

/*
 * @Brief WiFi信息描述
 * */
struct WiFiInfoDes{
	//名称
	std::string mName;
	//加密类型
	std::string mEncryptionType;
	//信号强度
	std::string mlevelDes;
	//信号强度图标
	int mLevelIcon;
	//站点的 MAC 地址
	std::string mBssid;
};
}

class ColdOnThread: public Thread {
 public:
   virtual bool threadLoop() {
//     LOGD("线程循环函数");
     //检查是否有退出线程的请求，如果有，则返回false，立即退出线程
     if (exitPending()) {
       return false;
     }

     if(Global::Timer::compressorTime > COMPRESSORTIME) {
    	 if(isColdOpen())
    	 {
 			water::set_task_load(E_TASK_ID_STOP_REFRIGERATION, true, {	E_DEV_LOAD_TYPE_COMPRESSOR, E_DEV_LOAD_TYPE_INTAKE_FAN,
 					E_DEV_LOAD_TYPE_CONDENSER_FAN, E_DEV_LOAD_TYPE_CIRCULATION_PUMP});
 	        if (!water::is_timer_event_running(E_TIMER_EVENT_ICE_ADD_WATER)) {
 	            water::start_timer_event(E_TIMER_EVENT_ICE_ADD_WATER);
 	        }
    	 }
    	 return false;
     }

     sleep(1000);

     return true;
   }
};
static ColdOnThread coldOn;

class DefrostThread: public Thread {
 public:
   virtual bool threadLoop() {
//     LOGD("线程循环函数");
     //检查是否有退出线程的请求，如果有，则返回false，立即退出线程
     if (exitPending()) {
       return false;
     }

     if(Global::Timer::compressorTime > COMPRESSORTIME) {
    	 if(Global::Flags::forceDefrost)
    	 {
 			Global::Flags::ice_sheded =false;
 			Global::Flags::start_ice =false;
 			water::stop_timer_event(E_TIMER_EVENT_MAKE_ALLICE, false);
 			water::set_task_load(E_TASK_ID_MAKE_ICE, true, {	E_DEV_LOAD_TYPE_COMPRESSOR,
 					E_DEV_LOAD_TYPE_HEAT_FILM, E_DEV_LOAD_TYPE_ICE_OUT, E_DEV_LOAD_TYPE_PUSH_FORWARD});
    	 }
    	 return false;
     }

     sleep(1000);
     return true;
   }
};
static DefrostThread forceOn;

void forceDefrost(bool is_act){
	Global::Flags::forceDefrost = is_act;
	if(is_act){
		mIceMakingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/IceMaking_Deicing.png");
		if(isCompressor() || Global::Timer::compressorTime > COMPRESSORTIME){
			Global::Flags::ice_sheded =false;
			Global::Flags::start_ice =false;
			water::stop_timer_event(E_TIMER_EVENT_MAKE_ALLICE, false);
			water::set_task_load(E_TASK_ID_MAKE_ICE, true, {	E_DEV_LOAD_TYPE_COMPRESSOR,
					E_DEV_LOAD_TYPE_HEAT_FILM, E_DEV_LOAD_TYPE_ICE_OUT, E_DEV_LOAD_TYPE_PUSH_FORWARD});
		}
		else
		{
			forceOn.run();
		}
	}else{
		buttonForce(is_act);
		water::stop_timer_event(E_TIMER_EVENT_FORCE_OUT);
		Global::Timer::compressorTime = 0;
		if(forceOn.isRunning())forceOn.requestExit();
		if(isIceOpen()){
        	water::start_timer_event(E_TIMER_EVENT_ICE_ADD_BLOCK);
        	Global::Flags::start_ice = true;
			mIceMakingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/IceMaking_InProgress.png");
		}else{
			mIceMakingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/IceMaking_Off.png");
		}
	}
}

void internalClean(bool is_act){
	Global::Flags::internalCleaning = is_act;

	if(is_act){
		Global::Flags::ice_sheded =false;
		Global::Flags::start_ice =true;
		water::stop_timer_event(E_TIMER_EVENT_MAKE_ALLICE);
		mIceMakingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/IceMaking_Cleaning.png");
		water::start_timer_event(E_TIMER_EVENT_ICE_ADD_BLOCK);
	}else{
		buttonClean(is_act);
		water::stop_timer_event(E_TIMER_EVENT_INTER_CLEAN);
		if(isIceOpen()){
        	water::start_timer_event(E_TIMER_EVENT_ICE_ADD_BLOCK);
        	Global::Flags::start_ice = true;
			mIceMakingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/IceMaking_InProgress.png");
		}else{
			water::set_task_load(E_TASK_ID_MAKE_ICE, false, { E_DEV_LOAD_TYPE_MAKEICE_IN } );
			mIceMakingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/IceMaking_Off.png");
		}
	}
}

//冰水箱防冻
static void Antifreezing(){

	static int ballLow = 0;

	if(Cur_a2.ColdWaterTankNTCTemp <= Global::Water::coldTemp){
		Global::Timer::freezingOffS++;
		if(Global::Timer::freezingOffS == 5){
			if(!water::is_timer_event_running(E_TIMER_EVENT_STOP_REFRIGERATION)){
				water::start_timer_event(E_TIMER_EVENT_STOP_REFRIGERATION);
			}
			Global::Timer::compressorTime = 0;
			mCoolingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/Cooling_Completed.png");
		}
		if( ( Cur_a2.ColdWaterTankNTCTemp ) <= 2 && Global::Timer::freezingOffS >= 2){
			getProtocolParam().control_aa_a1.CmdColdWaterTankAntiFreeze = true;
			mCoolingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/Cooling_AntiFreeze.png");
		}
	}
	else{
		Global::Timer::freezingOffS = 0;
	}

	if(Cur_a2.ColdWaterTankNTCTemp >= 5 && getProtocolParam().control_aa_a1.CmdColdWaterTankAntiFreeze){
		getProtocolParam().control_aa_a1.CmdColdWaterTankAntiFreeze = false;
	}
	if(Cur_a2.ColdWaterTankNTCTemp >= Global::Water::coldTemp + 5)
	{
		Global::Timer::freezingOnS++;
		if(Global::Timer::freezingOnS >= 5 && Global::Timer::compressorTime > COMPRESSORTIME){
			water::set_task_load(E_TASK_ID_STOP_REFRIGERATION, true, {	E_DEV_LOAD_TYPE_COMPRESSOR, E_DEV_LOAD_TYPE_INTAKE_FAN,
					E_DEV_LOAD_TYPE_CONDENSER_FAN, E_DEV_LOAD_TYPE_CIRCULATION_PUMP});
			mCoolingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/Cooling_InProgress.png");
		}
	}else{
		Global::Timer::freezingOnS = 0;
	}

	if(!Cur_a2.ColdWaterTankLowLevel && !Cur_a2.ColdWaterTankHighLevel){
		ballLow++;
		if(ballLow == 11){
			water::set_task_load(E_TASK_ID_STOP_REFRIGERATION, false, {E_DEV_LOAD_TYPE_COMPRESSOR},false);
			Global::Timer::compressorTime = 0;
			mCoolingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/Cooling_Completed.png");
		}
	}else{
		ballLow = 0;
		if( !isCompressor() && Cur_a2.ColdWaterTankLowLevel && Global::Timer::compressorTime > COMPRESSORTIME )
		{
			water::set_task_load(E_TASK_ID_STOP_REFRIGERATION, true, {	E_DEV_LOAD_TYPE_COMPRESSOR, });
			mCoolingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/Cooling_InProgress.png");
		}
	}

}

static void iceLoop(){
	Global::Timer::CountH++;
	if(Global::Timer::CountH == 3600){
		water::start_timer_event(E_TIMER_EVENT_ICE_STICK);
		Global::Timer::CountH = 0;
	}
	if(Global::Flags::ice_sheded)
	{
		static uint8_t timeCount = 0;
		if(Cur_a2.DeicingSensorAD < 100){
			timeCount++;
			if(timeCount == 3){
				Global::Flags::ice_full = true;
				mIceMakingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/IceMaking_Full.png");
				water::set_task_load(E_TASK_ID_MAKE_ICE, false, {E_DEV_LOAD_TYPE_COMPRESSOR, E_DEV_LOAD_TYPE_INTAKE_FAN});
				Global::Timer::compressorTime = 0;
			}
		}else{
			timeCount = 0;
		}

		//关了脱冰阀直接开启下轮循环 无论是否冰满
		if(!Cur_a2.RespDeicingValve &&Cur_a2.DeicingSensorAD > 1000){
			Global::Flags::ice_sheded =false;
			Global::Flags::ice_full = false;
			Global::Flags::start_ice =true;
			mIceMakingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/IceMaking_InProgress.png");
	        if (!water::is_timer_event_running(E_TIMER_EVENT_ICE_ADD_BLOCK) && !Cur_a2.IceMakingWaterLevel) {
	        	water::start_timer_event(E_TIMER_EVENT_ICE_ADD_BLOCK);
	        }

		}
	}

}


//滤芯快检闪烁
static void LvxinIconChange(){
	static bool stateLv = false;
	stateLv = !stateLv;
	stateLv? mFilterPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/Filter_Warning.png") : mFilterPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/Filter_Normal.png");

}

static void LvXinIcon(){
	if(water::get_cartridge_life(E_CARTRIDGE_TYPE_PPC) == 0 || water::get_cartridge_life(E_CARTRIDGE_TYPE_RO) == 0 ||
			water::get_cartridge_life(E_CARTRIDGE_TYPE_C2) == 0){
		mFilterPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/Filter_Expired.png");
	}
	else if((water::get_cartridge_life(E_CARTRIDGE_TYPE_PPC) <= 5 && water::get_cartridge_life(E_CARTRIDGE_TYPE_PPC) > 0) ||
	   (water::get_cartridge_life(E_CARTRIDGE_TYPE_RO) <= 5  && water::get_cartridge_life(E_CARTRIDGE_TYPE_RO)  > 0) ||
	   (water::get_cartridge_life(E_CARTRIDGE_TYPE_C2) <= 5 && water::get_cartridge_life(E_CARTRIDGE_TYPE_C2)   > 0)){
		mFilterPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/Filter_Warning.png");
	}
	else{
		mFilterPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/Filter_Normal.png");
	}
}

namespace{
struct tm *t = TimeHelper::getDateTime();
//设置后下次制冷制冰生效
class CustomIceThread: public Thread {
 public:
   virtual bool threadLoop() {
     //检查是否有退出线程的请求，如果有，则返回false，立即退出线程
     if (exitPending()) {
       return false;
     }
     sleep(1000);
     t = TimeHelper::getDateTime();
	 if(t->tm_hour == Global::Timer::iceHR && t->tm_min == Global::Timer::iceMR){
		 operateIce(false);
		 return false;
	 }
     return true;
   }
};
static CustomIceThread customIce;
class CustomColdThread: public Thread {
 public:
   virtual bool threadLoop() {
     //检查是否有退出线程的请求，如果有，则返回false，立即退出线程
     if (exitPending()) {
       return false;
     }
     sleep(1100);
     t = TimeHelper::getDateTime();
     if(t->tm_hour == Global::Timer::coldHR && t->tm_min == Global::Timer::coldMR){
     	 operateCold(false);
     	 return false;
     }

     return true;
   }
};
static CustomColdThread customCold;

}

//自动制冰块开关
bool operateIce(bool on) {
	if(isIceOpen() == on){	//已打开就不再打开
		return false;
	}
	if(on)
	{
		Global::Flags::Auto_iceing = true;
		if(water::get_water_state() != E_WATER_STATE_IDLE) {                 //如果正在出水的情况下就立即停水
			stop_water(true);
		}
		if(Global::Flags::custom_ice){
			customIce.run();
		}
		getProtocolParam().control_aa_a1.CmdDrainBoxPump = false;
		getProtocolParam().control_aa_a1.CmdOpenDeicingSensor = true;


	    if(!Global::Flags::forceDefrost && !Global::Flags::internalCleaning){
	    	Global::Flags::start_ice =true;
			water::start_timer_event(E_TIMER_EVENT_ICE_ADD_BLOCK);
			mIceMakingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/IceMaking_InProgress.png");
	    }
	}else{
		Global::Flags::Auto_iceing = false;
		if(water::get_water_state() != E_WATER_STATE_IDLE) {                 //如果正在出水的情况下就立即停水
			stop_water(true);
		}
		//退出自动停
		if(customIce.isRunning())customIce.requestExit();

		getProtocolParam().control_aa_a1.CmdOpenDeicingSensor = false;
	    if(!Global::Flags::forceDefrost && !Global::Flags::internalCleaning){
			mIceMakingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/IceMaking_Off.png");
			water::stop_timer_event(E_TIMER_EVENT_MAKE_ALLICE);
	    }


		if(!water::is_timer_event_running(E_TIMER_EVENT_MAKE_WATER_TIMEOUT)){
			getProtocolParam().control_aa_a1.CmdDrainBoxPump = true;		//打开“接水盒排水泵”负载
		}
	}
	return true;
}


//自动制冷水开关
bool operateCold(bool on) {
	if(isColdOpen() == on){	//已打开就不再打开
		return false;
	}
	if(on){

		Global::Flags::Auto_refriger = true;
		if(water::get_water_state() != E_WATER_STATE_IDLE) {                 //如果正在出水的情况下就立即停水
			stop_water(true);
		}
		if(Global::Flags::custom_cold){
			customCold.run();
		}
		if( isCompressor() || Global::Timer::compressorTime > COMPRESSORTIME ){
			water::set_task_load(E_TASK_ID_STOP_REFRIGERATION, true, {	E_DEV_LOAD_TYPE_COMPRESSOR, E_DEV_LOAD_TYPE_INTAKE_FAN,
					E_DEV_LOAD_TYPE_CONDENSER_FAN, E_DEV_LOAD_TYPE_CIRCULATION_PUMP});
	        if (!water::is_timer_event_running(E_TIMER_EVENT_ICE_ADD_WATER)) {
	            water::start_timer_event(E_TIMER_EVENT_ICE_ADD_WATER);
	        }
		}else{
			coldOn.run();
		}

		mCoolingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/Cooling_InProgress.png");

	}else{
		if(water::get_water_state() != E_WATER_STATE_IDLE) {                 //如果正在出水的情况下就立即停水
			stop_water(true);
		}
		//退出自动停
		if(customCold.isRunning())customCold.requestExit();
		if(coldOn.isRunning())coldOn.requestExit();

    	Global::Flags::Auto_refriger = false;
    	Global::Timer::compressorTime = 0;
    	mCoolingPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, "Status/Cooling_Off.png");
 		water::start_timer_event(E_TIMER_EVENT_STOP_REFRIGERATION);
	}
	return true;
}

void operateLock(bool on) {
	if(on) {
		if(water::get_water_state() != E_WATER_STATE_IDLE){
			stop_water(true);
		}
		LOCK_SCREEN->lock();
	}else {
		LOCK_SCREEN->reset();	//触摸重置锁屏计数
		LOCK_SCREEN->screenOn();
		LOCK_SCREEN->unlock();
	}
}

static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
		{1,  1000},
		{2,  500},
};

static void initCustom(){
	Global::j_handler.loadFromFile();
	Global::Timer::singleice = Global::j_handler.getInt("icesize", TIME_POINT_600);
	Global::Timer::iceHL = Global::j_handler.getInt("starticeTH", Global::Timer::iceHL);
	Global::Timer::iceML = Global::j_handler.getInt("starticeTM", Global::Timer::iceML);

	Global::Timer::iceHR = Global::j_handler.getInt("endiceTH", 8);
	Global::Timer::iceMR = Global::j_handler.getInt("endiceTM", Global::Timer::iceMR);
	Global::Flags::custom_ice = Global::j_handler.getBool("customice", Global::Flags::custom_ice);

	Global::Timer::coldHL= Global::j_handler.getInt("startcoldTH", Global::Timer::coldHL);
	Global::Timer::coldML= Global::j_handler.getInt("startcoldTM", Global::Timer::coldML);
	Global::Timer::coldHR= Global::j_handler.getInt("endcoldTH", 8);
	Global::Timer::coldMR= Global::j_handler.getInt("endcoldTM", Global::Timer::coldMR);
	Global::Flags::custom_cold= Global::j_handler.getBool("customcold", Global::Flags::custom_cold);
	Global::Water::coldTemp= Global::j_handler.getInt("coldTemp", Global::Water::coldTemp);

	Global::Water::ledType = Global::j_handler.getInt("ledType", Global::Water::ledType);
	Global::Water::ledTime = Global::j_handler.getInt("ledTime", Global::Water::ledTime);
}

/**
 * 当界面构造时触发
 */
static void onUI_init(){

	WIFIMANAGER->enableWifi(true);

    mSetPtr->setLongClickListener(&longButtonClickListener);

    initCustom();

	if(StoragePreferences::getInt("AutoTime", 1))synchronization_time();

}

/*
 * 当界面完全退出时触发
 */
static void onUI_quit() {
    mSetPtr->setLongClickListener(NULL);
}

/**
 * 串口数据回调接口
 */
static void onProtocolDataUpdate(const SProtocolData &data) {

	if(data.inquiry_a2.DeicingSensorAD < 100 ){
		if(water::is_timer_event_running(E_TIMER_EVENT_FORCE_OUT)){
			forceDefrost(false);
		}

		if(Global::Flags::ice_sheded && !Global::Flags::ice_full){
			water::set_task_load(E_TASK_ID_MAKE_ICE, false, {E_DEV_LOAD_TYPE_ICE_OUT}, false);
			water::set_task_load(E_TASK_ID_MAKE_ICE, true, {E_DEV_LOAD_TYPE_CONDENSER_FAN});
		}
	}

	if(Global::Flags::shortcutOut)
	{
		static bool shorcut = false;
		if(Global::Flags::shortcutLong){
			if(data.inquiry_a2.IceDispenserMicroSwitch == 1){
				shorcut = true;
				water::set_task_load(E_TASK_ID_MOTOR_ICE, true, {E_DEV_LOAD_TYPE_MOTOR_FORWARD});
			}else if (shorcut && getProtocolParam().control_aa_a1.CmdIceDispenserMotorForward) {
				shorcut = false;
	            water::start_timer_event(E_TIMER_EVENT_STOP_ICE, TIME_POINT_2);
	        }
		}
		else
		{
			if(data.inquiry_a2.pre_IceMicroSwitch == 0 && data.inquiry_a2.IceDispenserMicroSwitch == 1){
				if(getProtocolParam().control_aa_a1.CmdIceDispenserMotorForward){
					 water::start_timer_event(E_TIMER_EVENT_STOP_ICE, TIME_POINT_2);
				}else{
					water::set_task_load(E_TASK_ID_MOTOR_ICE, true, {E_DEV_LOAD_TYPE_MOTOR_FORWARD});
				}
			}
		}
	}

}

/**
 * 定时器触发函数
 * 不建议在此函数中写耗时操作，否则将影响UI刷新
 * 参数： id
 *         当前所触发定时器的id，与注册时的id相同
 * 返回值: true
 *             继续运行当前定时器
 *         false
 *             停止运行当前定时器
 */
static bool onUI_Timer(int id){
	switch (id) {
	case 1:{
		Global::Timer::compressorTime++;
		if(Global::Flags::Auto_refriger){
			Antifreezing();
		}
		if(Global::Flags::Auto_iceing){
			iceLoop();
		}

		LOCK_SCREEN->timeRun();

//		LvXinIcon();
//		if(FlagLvxin){
//			LvxinIconChange();
//		}
	}break;
	case 2:{
		//wifi图标变化
		if(WIFIMANAGER->isConnected()){
			char buf[1024]={0};
			if(RetLev() == 5){
				snprintf(buf,sizeof(buf),"Status/WiFi_4@1x.png");
			}else if(RetLev() == 4){
				snprintf(buf,sizeof(buf),"Status/WiFi_3@1x.png");
			}else if(RetLev() == 3){
				snprintf(buf,sizeof(buf),"Status/WiFi_2@1x.png");
			}else if(RetLev() == 2){
				snprintf(buf,sizeof(buf),"Status/WiFi_1@1x.png");
			}else{
				snprintf(buf,sizeof(buf),"Status/WiFi_0@1x.png");
			}
			mWiFiPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, buf);
		}else{
			mWiFiPtr->setButtonStatusPic(ZK_CONTROL_STATUS_NORMAL, CONFIGMANAGER->getResFilePath("Status/WiFi_nosigle.png").c_str());

		}

		//刷新出水led灯
		mLightPtr->setSelected(protocol::getLoadSwitch(E_DEV_LOAD_TYPE_LED_LIGHT));
	}break;
		default:
			break;
	}
    return true;
}

/**
 * 有新的触摸事件时触发
 * 参数：ev
 *         新的触摸事件
 * 返回值：true
 *            表示该触摸事件在此被拦截，系统不再将此触摸事件传递到控件上
 *         false
 *            触摸事件将继续传递到控件上
 */
static bool onstatusbarActivityTouchEvent(const MotionEvent &ev) {
	LOCK_SCREEN->reset();	//触摸重置锁屏计数
	if(LOCK_SCREEN->getStatus() == E_LOCK_STATUS_SCREEN_OFF) {	//熄屏状态触摸开屏
		LOCK_SCREEN->screenOn();
	}
    switch (ev.mActionStatus) {
		case MotionEvent::E_ACTION_DOWN://触摸按下
			//LOGD("时刻 = %ld 坐标  x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
			break;
		case MotionEvent::E_ACTION_MOVE://触摸滑动
			break;
		case MotionEvent::E_ACTION_UP:  //触摸抬起
			break;
		default:
			break;
	}
	return false;
}

static bool onButtonClick_Lock(ZKButton *pButton) {
    LOGD(" ButtonClick Lock !!!\n");
    operateLock(true);
    return false;
}

static bool onButtonClick_sys_home(ZKButton *pButton) {
    LOGD(" ButtonClick sya_home !!!\n");
    hideWaterWnd();
	if(water::get_water_state() != E_WATER_STATE_IDLE){
		operateWater(false);
		operateIceCake(false);
	}
//    EASYUICONTEXT->openActivity("mainActivity");
    return false;
}

static bool onButtonClick_IceMaking(ZKButton *pButton) {
    LOGD(" ButtonClick IceMaking !!!\n");
    operateIce(!isIceOpen());
    return false;
}

static bool onButtonClick_Cooling(ZKButton *pButton) {
    LOGD(" ButtonClick Cooling !!!\n");
    operateCold(!isColdOpen());
    return false;
}

static bool onButtonClick_Light(ZKButton *pButton) {
    LOGD(" ButtonClick Light !!!\n");
    if(!protocol::ledControl(!pButton->isSelected())) {
        LOGD("ledControl failed\n");
    }
    return false;
}

static bool onButtonClick_Filter(ZKButton *pButton) {
    LOGD(" ButtonClick Filter !!!\n");
	if(water::get_water_state() != E_WATER_STATE_IDLE) {
		stop_water(true);
	}
    EASYUICONTEXT->openActivity("LvxinActivity");
    return false;
}

static bool onButtonClick_WiFi(ZKButton *pButton) {
    LOGD(" ButtonClick WiFi !!!\n");
    EASYUICONTEXT->openActivity("wifiActivity");
//    EASYUICONTEXT->openActivity("WifiSettingActivity");
    return false;
}

static bool onButtonClick_Set(ZKButton *pButton) {
    LOGD(" ButtonClick Set !!!\n");
    EASYUICONTEXT->openActivity("setActivity");
    return false;
}
